<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      .container {
        padding: 20px;
        width: 100%;
        height: 100vh;
      }
      .hover-sec {
        width: 200px;
        height: 40px;
        background-color: blue;
        border-radius: 5px;
        position: relative;
        cursor: pointer;
      }
      .fold-sec {
        overflow: hidden;
        width: 100%;
        height: 0px;
        transition: height 0.2s ease-in-out;
        position: absolute;
        top: 100%;
        background-color: red;
        border-radius: 5px;
      }
      .fold-sec p {
        padding: 10px;
        color: #fff;
        font-size: 14px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="hover-sec">
        <div class="fold-sec">
          <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Tenetur
            quo saepe, accusantium perferendis qui fugit iste recusandae nemo
            aliquid nam temporibus rem odit esse distinctio hic enim ipsam non
            nulla.
          </p>
        </div>
      </div>
    </div>
  </body>

  <script>
    const hoverSec = document.querySelector('.hover-sec')
    const foldSec = document.querySelector('.fold-sec')

    hoverSec.addEventListener('mouseenter', () => {
      foldSec.style.height = 'auto'
      const height = foldSec.getBoundingClientRect().height
      foldSec.style.height = 0 // Reset height to 0 before setting the new height
      foldSec.getBoundingClientRect() // Force reflow
      foldSec.style.height = height + 'px'
    })

    hoverSec.addEventListener('mouseleave', () => {
      foldSec.style.height = 0
    })
  </script>
</html>
